package test;

import jdclib.io.Parseable;

public class Person implements Parseable<Person>
{
	private static final String INSTANCE_DELIMITER_STRING = "*";
	private static final byte[] INSTANCE_DELIMITER_BYTEARRAY = Person.INSTANCE_DELIMITER_STRING.getBytes();
	private static final boolean SKIP_NEW_LINES = true;
	private static final boolean RETURN_INSTANCE_DELIMITER = false;
	private static final String FIELD_DELIMITER = ",";
	
	public String FirstName;
	public String LastName;
	public int Age;
	
	public Person()
	{
		
	}
	
	public Person(byte[] data)
	{
		String[] args = new String(data).split(Person.FIELD_DELIMITER);
		this.LastName = args[0];
		this.FirstName = args[1];
		this.Age = Integer.parseInt(args[2]);
	}
	
	public Person(String firstName, String lastName, int age)
	{
		this.FirstName = firstName;
		this.LastName = lastName;
		this.Age = age;
	}

	@Override
	public byte[] getDelimiterValue()
	{
		return Person.INSTANCE_DELIMITER_BYTEARRAY;
	}

	@Override
	public Person parse(byte[] data)
	{
		return new Person(data);
	}

	@Override
	public boolean returnDelimiter()
	{
		return Person.RETURN_INSTANCE_DELIMITER;
	}

	@Override
	public boolean skipNewLines()
	{
		return Person.SKIP_NEW_LINES;
	}
	
	
	@Override
	public String toString()
	{
		return String.format("FirstName: %s, LastName: %s, Age: %d", FirstName, LastName, Age);
	}
	
	
}
